package com.itheima.controller;

import com.itheima.common.entity.Result;
import com.itheima.pojo.BusinessReport;
import com.itheima.pojo.MemberVO;
import com.itheima.pojo.SetmealVO;
import com.itheima.service.ReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/report")
@Slf4j
@Api(tags = "数据统计相关接口")
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * 会员数量统计
     * @return
     */
    @GetMapping("getMemberReport")
    @ApiOperation("会员数量统计")
    public Result<MemberVO> memberStatistics () {
        MemberVO memberVO = reportService.getMemberStatistics();
        return Result.success(memberVO);
    }

    /**
     * 套餐数量统计
     * @return
     */
    @GetMapping("getSetmealReport")
    @ApiOperation("套餐数量统计")
    public Result<SetmealVO> setmealStatistics () {
        SetmealVO setmealVO = reportService.getSetmealStatistics();
        return Result.success(setmealVO);
    }

    /**
     * 获取运营统计数据
     * @return
     */
    @GetMapping("getBusinessReportData")
    @ApiOperation("获取运营统计数据")
    public Result<BusinessReport> businessStatistics () {
        BusinessReport businessReport = reportService.businessStatistics();
        return Result.success(businessReport);
    }

    @GetMapping("/exportBusinessReport")
    @ApiOperation("模板下载并填充数据")
    public Result export (HttpServletResponse response) {
        reportService.export(response);
        return Result.success();
    }
}
